import getImage from './getImage';
import printCanvas from './printCanvas';

const filterImage = function (canvas, filter, image, amount = 0) {
  if (!canvas || !image) {
    return null;
  }
  // 先在canvas上画原图
  var ctx = canvas.getContext('2d');
  let rect = canvas.getBoundingClientRect();
  ctx.drawImage(image, 0, 0, rect.width, rect.height);
  // 再通过滤镜函数处理对应效果图像数据
  let args = [getImage(canvas, image), amount, canvas];
  // 最后渲染处理后的图像信息
  return printCanvas(canvas, filter.apply(null, args));
}

export default filterImage;
